<template>
  <view>
    <view class="wrap">
      <view class="notic_title">
        <view class="wei" :class="index==1?'active':''" @click="chgindex(1)">
          整租
        </view>
        <view class="yi" :class=" index==2?'active':''" @click="chgindex(2)">
          合租
        </view>
      </view>
      <add-all-house v-if="index==1" :model="model" @submit="addhouse"></add-all-house>
      <add-sub-house v-else :model="model" @submit="addhouse"></add-sub-house>
    </view>
  </view>
</template>

<script>
import addAllHouse from '@/components/zy/addAllHouse.vue'
import addSubHouse from '@/components/zy/addSubHouse.vue'
export default {
  // 本地保存的房源信息
  onLoad(option) {
    this.index = option.index
    this.getHouseList()
  },
  components: {
    addAllHouse,
    addSubHouse
  },
  methods: {
    getHouseList() {
      uni.getStorage({
        key: 'houseList',
        success: (res) => {
          // console.log(res)
          this.houstList = JSON.parse(res.data)
        }
      })
    },
    async addhouse(house) {
      house.heart = false;
      let url = `http://127.0.0.1/addhouse`
      let [, result] = await uni.request({
        url: url,
        data: { model: JSON.stringify(house) },
        method: 'GET'
      })
      uni.showToast({
        icon: 'success',
        title: '保存成功'
      })
      setTimeout(() => {
        uni.redirectTo({
          url: '/pages/index/index'
        })
      }, 1000)
      const data = result.data.data
    },
    chgindex(i) {
      this.index = i
    }
  },
  data() {
    return {
      houstList: [],
      index: 1,
      tabList: [{ name: '整租' }, { name: '合租' }],
      current: 0,
      swiperCurrent: 0,
      tabsHeight: 0,
      // 房源对象
      model: null
    }
  }
}
</script>

<style lang="scss">
.notic_title {
  height: 100rpx;
  line-height: 100rpx;
  background-color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-around;
  .wei,
  .yi {
    padding: 0rpx 40rpx;
    border-bottom: 8rpx solid transparent;
  }
  .active {
    color: #00f;
    border-bottom: 8rpx solid #00f;
  }
}
</style>
